/**
 * Copyright 2010 - YangJiandong(chunquedong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * ChunMap是开源软件。你可以自由复制、传播本项目的下载包文件，但必须保持其完整性。
 * 我们不用对使用中的风险及由此造成的损失承担任何责任。
 * 详细情况请见《ChunMap许可协议》。
 * 
 * 想了解更多有关ChunMap的信息，请访问http://code.google.com/p/chunmap/
 * 
 * 下面此段程序作者YangJianDong(chunquedong)
 * 最后修改时间2010.7.17
 */
package chunmap.model.crs.proj;

import chunmap.data.feature.Feature;
import chunmap.data.feature.FeatureCollection;
import chunmap.data.feature.LayerMetadata;
import chunmap.data.feature.VisitAction;
import chunmap.model.crs.CoordinateRSystem;
import chunmap.view.layer.Layer;
import chunmap.view.layer.LayerCollection;
import chunmap.view.layer.VectorLayer;

public class ReProjOp {
	public static void changeCRS(FeatureCollection fc,CoordinateRSystem target)
    {
        CoordinateRSystem source = fc.getMetadata().getCrs();
        final ReProjection rp = new ReProjection(target, source);

        fc.each(new VisitAction(){
			@Override
			public void execute(Feature f) {
				rp.execute(f);
			}});

        fc.setMetadata(new LayerMetadata
        		(fc.getMetadata().getName(),fc.getMetadata().getType(),target));
        fc.reComputeEnvelope();
    }

    public static void changeMapCRS(LayerCollection layers, CoordinateRSystem target)
    {
    	for(Layer layer:layers.getLayers()){
            if (layer instanceof VectorLayer)
            {
                VectorLayer vl = (VectorLayer)layer;
                changeCRS(vl.getFeatures(), target);
            }
        }
        layers.reComputeEnvelop();
    }
}
